﻿using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using CoachingOrganizer.Logic.Models.Common;
using CoachingOrganizer.iOS.Common;

namespace CoachingOrganizer.iOS
{
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS.
    [Register("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {

        private readonly Lazy<InteractionModel> _rootModel = new Lazy<InteractionModel>(() => new InteractionModel(new iOSLogicExtender()));

        public InteractionModel RootModel
        {
            get { return _rootModel.Value; }
        }


        // class-level declarations
        public override UIWindow Window { get; set; }

        public override void WillTerminate(UIApplication application)
        {
            base.WillTerminate(application);
            if (_rootModel.IsValueCreated)
                _rootModel.Value.Dispose();
        }
    }
}